﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using IGGCore;

namespace IGGWindowApp.Panels
{
    public partial class PanelLineup : UserControl
    {
        public PanelLineup()
        {
            InitializeComponent();
        }

        private Player GetPlayer(string id, List<Player> players)
        {
            Player result = null;
            foreach (Player player in players)
            {
                if (player.Id == id)
                {
                    result = player;
                    break;
                }
            }
            return result;
        }

        public void SetData(Game game)
        {
            lblTeam1.Text = game.AwayTeam.Name;
            lblTeam2.Text = game.HomeTeam.Name;

            if (game.AwayTeam.Lineup[0]!=null)
            {
                lblAway1.Text = game.AwayTeam.Lineup[0].FullName;
                lblAway2.Text = game.AwayTeam.Lineup[1].FullName;
                lblAway3.Text = game.AwayTeam.Lineup[2].FullName;
                lblAway4.Text = game.AwayTeam.Lineup[3].FullName;
                lblAway5.Text = game.AwayTeam.Lineup[4].FullName;
                lblAway6.Text = game.AwayTeam.Lineup[5].FullName;
                lblAway7.Text = game.AwayTeam.Lineup[6].FullName;
                lblAway8.Text = game.AwayTeam.Lineup[7].FullName;
                lblAway9.Text = game.AwayTeam.Lineup[8].FullName;

                Player away1 = GetPlayer(game.AwayTeam.Lineup[0].Id, game.Boxscore.AwayBatting);
                lblAwayAB1.Text = away1.Ab.ToString();
                lblAwayH1.Text = away1.Hits.ToString();
                lblAwayRBI1.Text = away1.RBI.ToString();
                lblAwayAVG1.Text = away1.AVG;

                Player away2 = GetPlayer(game.AwayTeam.Lineup[1].Id, game.Boxscore.AwayBatting);
                lblAwayAB2.Text = away2.Ab.ToString();
                lblAwayH2.Text = away2.Hits.ToString();
                lblAwayRBI2.Text = away2.RBI.ToString();
                lblAwayAVG2.Text = away2.AVG;

                Player away3 = GetPlayer(game.AwayTeam.Lineup[2].Id, game.Boxscore.AwayBatting);
                lblAwayAB3.Text = away3.Ab.ToString();
                lblAwayH3.Text = away3.Hits.ToString();
                lblAwayRBI3.Text = away3.RBI.ToString();
                lblAwayAVG3.Text = away3.AVG;

                Player away4 = GetPlayer(game.AwayTeam.Lineup[3].Id, game.Boxscore.AwayBatting);
                lblAwayAB4.Text = away4.Ab.ToString();
                lblAwayH4.Text = away4.Hits.ToString();
                lblAwayRBI4.Text = away4.RBI.ToString();
                lblAwayAVG4.Text = away4.AVG;

                Player away5 = GetPlayer(game.AwayTeam.Lineup[4].Id, game.Boxscore.AwayBatting);
                lblAwayAB5.Text = away5.Ab.ToString();
                lblAwayH5.Text = away5.Hits.ToString();
                lblAwayRBI5.Text = away5.RBI.ToString();
                lblAwayAVG5.Text = away5.AVG;

                Player away6 = GetPlayer(game.AwayTeam.Lineup[5].Id, game.Boxscore.AwayBatting);
                lblAwayAB6.Text = away6.Ab.ToString();
                lblAwayH6.Text = away6.Hits.ToString();
                lblAwayRBI6.Text = away6.RBI.ToString();
                lblAwayAVG6.Text = away6.AVG;

                Player away7 = GetPlayer(game.AwayTeam.Lineup[6].Id, game.Boxscore.AwayBatting);
                lblAwayAB7.Text = away7.Ab.ToString();
                lblAwayH7.Text = away7.Hits.ToString();
                lblAwayRBI7.Text = away7.RBI.ToString();
                lblAwayAVG7.Text = away7.AVG;

                Player away8 = GetPlayer(game.AwayTeam.Lineup[7].Id, game.Boxscore.AwayBatting);
                lblAwayAB8.Text = away8.Ab.ToString();
                lblAwayH8.Text = away8.Hits.ToString();
                lblAwayRBI8.Text = away8.RBI.ToString();
                lblAwayAVG8.Text = away8.AVG;

                Player away9 = GetPlayer(game.AwayTeam.Lineup[8].Id, game.Boxscore.AwayBatting);
                lblAwayAB9.Text = away9.Ab.ToString();
                lblAwayH9.Text = away9.Hits.ToString();
                lblAwayRBI9.Text = away9.RBI.ToString();
                lblAwayAVG9.Text = away9.AVG;

                lblHome1.Text = game.HomeTeam.Lineup[0].FullName;
                lblHome2.Text = game.HomeTeam.Lineup[1].FullName;
                lblHome3.Text = game.HomeTeam.Lineup[2].FullName;
                lblHome4.Text = game.HomeTeam.Lineup[3].FullName;
                lblHome5.Text = game.HomeTeam.Lineup[4].FullName;
                lblHome6.Text = game.HomeTeam.Lineup[5].FullName;
                lblHome7.Text = game.HomeTeam.Lineup[6].FullName;
                lblHome8.Text = game.HomeTeam.Lineup[7].FullName;
                lblHome9.Text = game.HomeTeam.Lineup[8].FullName;

                Player home1 = GetPlayer(game.HomeTeam.Lineup[0].Id, game.Boxscore.HomeBatting);
                lblHomeAB1.Text = home1.Ab.ToString();
                lblHomeH1.Text = home1.Hits.ToString();
                lblHomeRBI1.Text = home1.RBI.ToString();
                lblHomeAVG1.Text = home1.AVG;

                Player home2 = GetPlayer(game.HomeTeam.Lineup[1].Id, game.Boxscore.HomeBatting);
                lblHomeAB2.Text = home2.Ab.ToString();
                lblHomeH2.Text = home2.Hits.ToString();
                lblHomeRBI2.Text = home2.RBI.ToString();
                lblHomeAVG2.Text = home2.AVG;

                Player home3 = GetPlayer(game.HomeTeam.Lineup[2].Id, game.Boxscore.HomeBatting);
                lblHomeAB3.Text = home3.Ab.ToString();
                lblHomeH3.Text = home3.Hits.ToString();
                lblHomeRBI3.Text = home3.RBI.ToString();
                lblHomeAVG3.Text = home3.AVG;

                Player home4 = GetPlayer(game.HomeTeam.Lineup[3].Id, game.Boxscore.HomeBatting);
                lblHomeAB4.Text = home4.Ab.ToString();
                lblHomeH4.Text = home4.Hits.ToString();
                lblHomeRBI4.Text = home4.RBI.ToString();
                lblHomeAVG4.Text = home4.AVG;

                Player home5 = GetPlayer(game.HomeTeam.Lineup[4].Id, game.Boxscore.HomeBatting);
                lblHomeAB5.Text = home5.Ab.ToString();
                lblHomeH5.Text = home5.Hits.ToString();
                lblHomeRBI5.Text = home5.RBI.ToString();
                lblHomeAVG5.Text = home5.AVG;

                Player home6 = GetPlayer(game.HomeTeam.Lineup[5].Id, game.Boxscore.HomeBatting);
                lblHomeAB6.Text = home6.Ab.ToString();
                lblHomeH6.Text = home6.Hits.ToString();
                lblHomeRBI6.Text = home6.RBI.ToString();
                lblHomeAVG6.Text = home6.AVG;

                Player home7 = GetPlayer(game.HomeTeam.Lineup[6].Id, game.Boxscore.HomeBatting);
                lblHomeAB7.Text = home7.Ab.ToString();
                lblHomeH7.Text = home7.Hits.ToString();
                lblHomeRBI7.Text = home7.RBI.ToString();
                lblHomeAVG7.Text = home7.AVG;

                Player home8 = GetPlayer(game.HomeTeam.Lineup[7].Id, game.Boxscore.HomeBatting);
                lblHomeAB8.Text = home8.Ab.ToString();
                lblHomeH8.Text = home8.Hits.ToString();
                lblHomeRBI8.Text = home8.RBI.ToString();
                lblHomeAVG8.Text = home8.AVG;

                Player home9 = GetPlayer(game.HomeTeam.Lineup[8].Id, game.Boxscore.HomeBatting);
                lblHomeAB9.Text = home9.Ab.ToString();
                lblHomeH9.Text = home9.Hits.ToString();
                lblHomeRBI9.Text = home9.RBI.ToString();
                lblHomeAVG9.Text = home9.AVG;
            }
            else
            {
                lblAway1.Text = "...";
                lblAway2.Text = "...";
                lblAway3.Text = "...";
                lblAway4.Text = "...";
                lblAway5.Text = "...";
                lblAway6.Text = "...";
                lblAway7.Text = "...";
                lblAway8.Text = "...";
                lblAway9.Text = "...";

                lblAwayAB1.Text = "-";
                lblAwayAB2.Text = "-";
                lblAwayAB3.Text = "-";
                lblAwayAB4.Text = "-";
                lblAwayAB5.Text = "-";
                lblAwayAB6.Text = "-";
                lblAwayAB7.Text = "-";
                lblAwayAB8.Text = "-";
                lblAwayAB9.Text = "-";

                lblHome1.Text = "...";
                lblHome2.Text = "...";
                lblHome3.Text = "...";
                lblHome4.Text = "...";
                lblHome5.Text = "...";
                lblHome6.Text = "...";
                lblHome7.Text = "...";
                lblHome8.Text = "...";
                lblHome9.Text = "...";

                lblHomeAB1.Text = "-";
                lblHomeAB2.Text = "-";
                lblHomeAB3.Text = "-";
                lblHomeAB4.Text = "-";
                lblHomeAB5.Text = "-";
                lblHomeAB6.Text = "-";
                lblHomeAB7.Text = "-";
                lblHomeAB8.Text = "-";
                lblHomeAB9.Text = "-";
            }
        }
    }
}
